<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>库存管理系统-登陆</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="lay/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="lay/style/admin.css" media="all">
    <link rel="stylesheet" href="lay/style/login.css" media="all">
    <script src="util/httpUtil.js"></script>
</head>
<body>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>库存管理系统</h2>
        </div>
        <div class="layui-form">
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                           for="LAY-user-login-username"></label>
                    <input type="text" name="userName" id="LAY-user-login-username" lay-verify="required"
                           placeholder="用户名" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                           for="LAY-user-login-password"></label>
                    <input type="password" name="password" id="LAY-user-login-password" lay-verify="required"
                           placeholder="密码" class="layui-input">
                </div>
                <div class="layui-form-item" style="margin-bottom: 20px;">
                    <a href="javascript:alert('请联系管理员')" class="layadmin-user-jump-change layadmin-link"
                       style="margin-top: 7px;">忘记密码？</a>
                </div>

                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid"  lay-submit lay-filter="login" type="button">登 陆</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="lay/layui/layui.js"></script>
<script>
    layui.use(['jquery','form','layer'],function () {
      var form = layui.form;
      var $ = layui.jquery;

      form.on('submit(login)', function(data){
        HTTPUtil.post('/user/sysUser/login', data.field)
            .then(function (json) {
              console.log(json);
              if (json.state === 'success') {
                localStorage.setItem('userName',json.data.name);
                localStorage.setItem('userId',json.data.id);
                layer.msg(json.msg,{icon: 1});
                window.location.href = '/index.html'
              } else {
                layer.msg(json.msg,{icon: 2});
              }
            })
      });
    })
</script>
</body>
</html>